<?php
namespace api\modules\v1\controllers;

use Yii;
use yii\web\HttpException;
use api\modules\v1\resources\MappErrorLog;
use common\core\base\BaseApiActiveController;

class MappErrorLogController extends BaseApiActiveController
{

    public $modelClass = 'api\modules\v1\resources\MappErrorLog';

    public $needLogin = false;

    /**
     * @inheritdoc
     */
    public function actions()
    {
        return [
            'view' => [
                'class' => 'yii\rest\ViewAction',
                'modelClass' => $this->modelClass,
                'findModel' => [
                    $this,
                    'findModel'
                ]
            ],
            'create' => [
                'class' => 'yii\rest\CreateAction',
                'modelClass' => $this->modelClass,
                'checkAccess' => [
                    $this,
                    'checkAccess'
                ],
                'scenario' => $this->createScenario
            ]
        ];
    }

    /**
     *
     * @param
     *            $id
     * @return array|null|\yii\db\ActiveRecord
     * @throws HttpException
     */
    public function findModel($id)
    {
        $model = MappErrorLog::find()->andWhere([
            'id' => (int) $id
        ])->one();
        if (! $model) {
            throw new HttpException(404);
        }
        return $model;
    }
}